<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>index页面</h2>
    <iframe src="http://localhost:3000" frameborder="0" id="iframe" onload="load()"></iframe>
</body>
<script>
    window.addEventListener('message', ev => {
        const { data, origin, source } = ev
        if (origin !== 'http://localhost:3000') return
        console.log('接收iframe页面发送的消息：', data)
    })
    function load() {
        iframe.contentWindow.postMessage("给iframe页面发送的消息", "http://localhost:3000");
    }
</script>

</html>